package com.jmex.physics.impl.bullet.geometry;

import com.jme.math.Quaternion;
import com.jmex.physics.PhysicsNode;
import com.jmex.physics.geometry.PhysicsSphere;

public class BulletSphere extends PhysicsSphere implements BulletGeometry {

    private boolean dirty;
    private com.jme.math.Vector3f previousScale = new com.jme.math.Vector3f();
    private Quaternion previousRotation = new Quaternion();
    private com.jme.math.Vector3f previousTranslation = new com.jme.math.Vector3f();
	
	public BulletSphere(PhysicsNode node) {
		super(node);
	}

	public float[] getLocalRotationAsArray() {
		return new float[]{getLocalRotation().x,getLocalRotation().y,getLocalRotation().z,getLocalRotation().w};
	}

	public float[] getLocalScaleAsArray() {
		return new float[]{getLocalScale().x,getLocalScale().y,getLocalScale().z};
	}

	public float[] getLocalTranslationAsArray() {
		return new float[]{getLocalTranslation().x,getLocalTranslation().y,getLocalTranslation().z};
	}

	public Shape getShape() {
		return Shape.Sphere;
	}

	public int getShapeOrdinal() {
		return Shape.Sphere.ordinal();
	}

    public boolean isDirty() {
        if ( dirty ) {
            return true;
        }
        return !( getLocalTranslation().equals( previousTranslation ) &&
                getLocalRotation().equals( previousRotation ) &&
                getLocalScale().equals( previousScale ) );
    }

    public void setDirty( boolean value ) {
        dirty = value;
        if ( !value ) {
            previousTranslation.set( getLocalTranslation() );
            previousRotation.set( getLocalRotation() );
            previousScale.set( getLocalScale() );
        }
    }

}
